//
//  FavoriteView.m
//  体育
//
//  Created by liujianlong on 2022/10/24.
//

#import "FavoriteView.h"
@interface FavoriteView()
@property (strong, nonatomic) IBOutlet UIButton *selectBtn;
@property (strong, nonatomic) IBOutlet UILabel *title;
@property (strong, nonatomic) IBOutlet UILabel *detail;
@property (strong, nonatomic) IBOutlet UILabel *time;
@property (strong, nonatomic) IBOutlet UILabel *home;
@property (strong, nonatomic) IBOutlet UILabel *from;
@property (strong, nonatomic) IBOutlet UILabel *homeResult;
@property (strong, nonatomic) IBOutlet UILabel *fromResult;
@property (strong, nonatomic) IBOutlet UILabel *homeScore;
@property (strong, nonatomic) IBOutlet UILabel *fromScore;
@end
@implementation FavoriteView
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self loadView];
    }
    return self;
}

- (IBAction)actionForBtn:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.model.favorite =  !self.model.favorite;
    if (self.model.isbasketball) {
        for (Record *model in APP.basketRecord) {
            if (model.stamp == self.model.stamp) {
                model.favorite = self.model.favorite;
                break;
            }
        }
    }else{
        for (Record *model in APP.footRecord) {
            if (model.stamp == self.model.stamp) {
                model.favorite = self.model.favorite;
                break;
            }
        }
    }
    [CCHud msg:self.model.favorite ? LS(@"已经收藏") : LS(@"取消收藏")];
    [self.model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [NotifyTool post:notifyRecordUpdate :nil];
        });
    }];
}

- (void)setModel:(Record *)model{
    _model = model;
    self.title.text = @"";
    self.detail.text = @"";
    self.time.text = @"";
    self.home.text = @"";
    self.from.text = @"";
    self.homeResult.text = @"";
    self.fromResult.text = @"";
    self.homeScore.text = @"";
    self.fromScore.text = @"";
    self.selectBtn.selected = _model.favorite;
    if (_model.isbasketball) {
        self.title.text = [NSString stringWithFormat:@"%@%@",[NSDate transToDate:@"MM-dd" :_model.stamp],LS(_model.league_name)];
        self.home.text = LS(_model.home);
        self.from.text = LS(_model.from);
        self.homeResult.text = !_model.finish?@"":[NSString stringWithFormat:@"%d %d %d %d",_model.fir_score_home,_model.sec_score_home,_model.thrd_score_home,_model.fth_score_home];
        self.fromResult.text = !_model.finish?@"":[NSString stringWithFormat:@"%d %d %d %d",_model.fir_score_from,_model.sec_score_from,_model.thrd_score_from,_model.fth_score_from];
        self.time.text = !_model.finish?LS(@"未"):LS(@"完");
        self.homeScore.text = !_model.finish?@"":[NSString stringWithFormat:@"%d",_model.score_home];
        self.fromScore.text = !_model.finish?@"":[NSString stringWithFormat:@"%d",_model.score_from];
    }else{
        self.title.text = [NSString stringWithFormat:@"%@%@",LS(_model.league_name),[NSDate transToDate:@"MM-dd" :_model.stamp]];
        self.from.text = LS(_model.home);
        self.fromScore.text = LS(_model.from);
        self.fromResult.text = !_model.finish ? @"vs" : [NSString stringWithFormat:@"%d:%d",_model.score_home,_model.score_from];
        self.detail.text = !_model.finish?@"":@"90`";
        self.time.text = !_model.finish?@"":[NSString stringWithFormat:@"%@%d:%d",LS(@"半"),_model.top_half_score_home,_model.top_half_score_from];
        
    }
}

@end
